package com.tencent.iov.cowin.befsale.clue.controller.cus;

import com.alibaba.fastjson.JSON;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.AddClueCustomerFollowRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.QueryClueDetailRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.UpdateClueCustomerRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.UpdateClueEmpRequest;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.ClueDetailResponse;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.ClueDictionariesResponse;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.response.CustomerResponse;
import com.tencent.iov.cowin.befsale.clue.service.cus.ClueCustomerDetailService;
import com.software.boot.common.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Describe: 经销商客户详情_Controller层
 * @author: xiamu
 * @created: 2021-12-21 17:29:53
 * @version: 1.0
 */
@RestController
@RequestMapping(value = "/v1/befsale/clue/detail", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "经销商客户详情_Controller层")
@Slf4j
public class ClueCustomerDetailController {
    @Autowired
    private ClueCustomerDetailService clueCustomerDetailService;

    /**
     * 获取线索详情
     *
     * @param request 线索id
     * @return ClueDetailResponse对象
     */
    @ApiOperation(value = "通过参数获取详细信息接口", httpMethod = "POST", response = Response.class, notes = "get_detail_by_id")
    @PostMapping(path = "/get_detail_by_param")
    public Response<ClueDetailResponse> getDetailById(@RequestBody QueryClueDetailRequest request) {
        return Response.success(clueCustomerDetailService.getClueDetail(request));
    }

    @ApiOperation(value = "根据线索ID获取客户信息，客户手机号不加密不脱敏")
    @GetMapping("/get_customer_by_clue")
    public Response<CustomerResponse> getCustomerByCusId(@RequestParam("clueId")Long clueId){
        return Response.success(clueCustomerDetailService.getCustomerByCusId(clueId));
    }

    /**
     * 线索客户意向更新
     *
     * @param request 更新参数
     * @return 是否更新成功
     */
    @ApiOperation(value = "更新线索信息(客户、意向)", httpMethod = "POST", response = Response.class, notes = "update_customer_detail_by_param")
    @RequestMapping(path = "/update_customer_by_param", method = RequestMethod.POST)
    public Response<Boolean> updateClueCustomerByParam(@ApiParam(required = true, value = "线索客户意向更新参数信息", defaultValue = "1")
                                                       @RequestBody UpdateClueCustomerRequest request) {
        log.info("[updateClueCustomerByParam] request = {}", JSON.toJSONString(request));
        Boolean flag = clueCustomerDetailService.updateClueCustomerDetail(request);
        //客户信息编辑成功埋点
        clueCustomerDetailService.updateClueCustomerBackend(request);
        return Response.success(flag);
    }

    /**
     * 保存线索信息(跟进计划、跟进记录)
     *
     * @param request 更新参数
     * @return 是否更新成功
     */
    @ApiOperation(value = "保存线索信息(跟进计划、跟进记录)", httpMethod = "POST", response = Response.class, notes = "save_customer_follow_by_param")
    @RequestMapping(path = "/save_customer_follow_by_param", method = RequestMethod.POST)
    public Response<Boolean> saveClueCustomerFollowInfoByParam(@ApiParam(required = true, value = "保存线索信息(跟进计划、跟进记录)", defaultValue = "1")
                                                               @RequestBody AddClueCustomerFollowRequest request) {
        Boolean flag = clueCustomerDetailService.saveClueCustomerFollowInfoByParam(request);
        //线索跟进埋点
        clueCustomerDetailService.clueFollowBackend(request);
        return Response.success(flag);
    }

    /**
     * 分配顾问
     *
     * @param updateClueEmpRequest 分配顾问参数
     * @return 是否分配成功
     */
    @ApiOperation(value = "分配顾问(单个/批量)", httpMethod = "POST", response = Response.class, notes = "distribute_clue")
    @RequestMapping(path = "/update_clue_emp", method = RequestMethod.POST)
    public Response<Boolean> updateClueFollowEmp(@ApiParam(required = true, value = "线索跟进人信息", defaultValue = "updateClueEmpRequest")
                                                 @RequestBody UpdateClueEmpRequest updateClueEmpRequest) {
        return Response.success(clueCustomerDetailService.updateClueFollowEmp(updateClueEmpRequest));
    }

    /**
     * 战败审批-激活、同意、拒绝
     *
     * @param updateClueEmpRequest 分配顾问参数
     * @return 是否分配成功
     */
    @ApiOperation(value = "战败审批-激活、同意、拒绝", httpMethod = "POST", response = Response.class, notes = "update_fail_clue")
    @RequestMapping(path = "/update_fail_clue", method = RequestMethod.POST)
    public Response<Boolean> updateFailClue(@ApiParam(required = true, value = "战败审批信息", defaultValue = "updateClueEmpRequest")
                                                 @RequestBody UpdateClueEmpRequest updateClueEmpRequest) {
        Boolean flag = clueCustomerDetailService.updateFailClueFollow(updateClueEmpRequest);
        //战败审核同意 战败激活进行埋点
        clueCustomerDetailService.clueFailFollowBackend(updateClueEmpRequest);
        return Response.success(flag);
    }

    /**
     * 获取字典信息
     *
     * @param type 类型 标识意向/基本信息
     * @return 字典列表
     */
    @ApiOperation(value = "获取字典信息", httpMethod = "POST", response = Response.class, notes = "/dictionary/get_list_by_params")
    @RequestMapping(path = "/dictionary/get_list_by_params", method = RequestMethod.POST)
    public Response<List<ClueDictionariesResponse>> getListDictionaries(@ApiParam(required = true, value = "类型 1 标识意向/ 0 基本信息", defaultValue = "Integer")
                                                                        @RequestBody Integer type) {
        return Response.success(clueCustomerDetailService.getListDictionaries(type));
    }
}